<?php
require '../model/Db.php';
require '../model/Page.php';
$Db = Db::getInstance();
$admin_data = $Db->isadmin();
if(!$admin_data){
	$user_data = $Db->islogin();
	if($user_data['job'] == 3){
		$admin_data = $user_data;
	}
}
if(($admin_data || $user_data['job'] != 0) && is_numeric($_GET['id'])){
	$cnt_where = $_GET['id'] > 0 ? "and mid = {$_GET['id']}":'';
	$where = $_GET['id'] > 0 ? "and a.mid = {$_GET['id']}":'';
	$count =  $Db->count([
		table => ['content'],
		where => "delete_time is NULL {$cnt_where}"
	]);
	$page = page($count,50,5);
	$cont_data = $Db->find([
		table => [content => 'a',bbs_user => 'b',module => 'c'],
		field => 'a.title,a.time,a.id,b.user,a.uid,c.name',
		where => "a.uid = b.id and a.mid = c.id and a.delete_time is NULL {$where} order by a.time desc {$page['limit']}"
	]);
	$cont_data = $Db->tohtml($cont_data);
	$Db->close();
	foreach($cont_data as $item){
		$html .= <<<tr
				<tr>
					<td>{$item['id']}</td>
					<td>{$item['name']}</td>
					<td class="c-tt"><a target="_blank" href="/nsbbs/details.php?cid={$item['id']}">{$item['title']}</a></td>
					<td><a target="_blank" href="/nsbbs/userinfo.php?uid={$item['uid']}">{$item['user']}</a></td>
					<td>{$item['time']}</td>
					<td><span class="btn" id="{$item['id']}">删除</span></td>
				</tr>
tr;

	}

	if(!$html){
		$html = '空空如也';
	}
	echo json_encode([html=>$html,page => $page['html']]);
}else{
	http_response_code(404);
	echo '<h1 style="color:#337ab7">千呼万唤始出来,犹抱琵琶半遮面</h1>';
}